<template xmlns:color="http://www.w3.org/1999/xhtml">
  <div class="app-container">
    <el-form size="medium" height="500px">
    <el-row>
      <h1 align="center" class="title">欢迎来到skpl社区问答</h1>



    </el-row>




    <el-row :gutter="10" class="mb8">
      <el-col :span="7">
        <el-button
          type="success"
          plain
          icon="el-icon-reading"
          size="medium"
          @click="handletoallquestion"
        >全部问题</el-button>
      </el-col>
        <el-col :span="6">
          <el-button
            type="success"

            plain
            icon="el-icon-view"
            size="medium"
            @click="labelquestion"
          >标签相关问题</el-button>
        </el-col>

      <el-col :span="6">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="medium"
          @click="hotanswer"
        >热门回答</el-button>
      </el-col>

      <el-col :span="5">

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        <h3 class="atitle">点击右侧搜索</h3>
      </el-col>
    </el-row>
    </el-form>


    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="问题标题" prop="questionTitle">
        <el-input
          v-model="queryParams.questionTitle"
          placeholder="请输入问题标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题简介" prop="questionResume">
        <el-input
          v-model="queryParams.questionResume"
          placeholder="请输入问题简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="questionUser">
        <el-input
          v-model="queryParams.questionUser"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="questionCreatetime">
        <el-date-picker clearable
                        v-model="queryParams.questionCreatetime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="喜欢人数" prop="questionFavorcount">
        <el-input
          v-model="queryParams.questionFavorcount"
          placeholder="请输入喜欢人数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收藏量" prop="questionCollectcount">
        <el-input
          v-model="queryParams.questionCollectcount"
          placeholder="请输入收藏量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="questionList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="问题id" align="center" prop="questionId" />-->
      <el-table-column label="问题标题" align="center" prop="questionTitle" />
      <el-table-column label="问题简介" align="center" prop="questionResume" />
      <el-table-column label="创建人" align="center" prop="questionUser" />
      <el-table-column label="创建时间" align="center" prop="questionCreatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.questionCreatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="喜欢人数" align="center" prop="questionFavorcount" />
      <el-table-column label="收藏量" align="center" prop="questionCollectcount" />
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template slot-scope="scope">-->

      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['system:question:edit']"-->
      <!--          >修改</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="hotanswer"-->
      <!--          >我要回答</el-button>-->

      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <el-row>
      <el-button
        style="float:right"
        align="right"
        size="medium"
        type="text"
        icon="el-icon-edit"
        @click="handledetail"
      >详情</el-button>
    </el-row>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />








    <!-- 添加或修改问题对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="问题标题" prop="questionTitle">
          <el-input v-model="form.questionTitle" placeholder="请输入问题标题" />
        </el-form-item>
        <el-form-item label="问题简介" prop="questionResume">
          <el-input v-model="form.questionResume" placeholder="请输入问题简介" />
        </el-form-item>
        <el-form-item label="创建人" prop="questionUser">
          <el-input v-model="form.questionUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="questionCreatetime">
          <el-date-picker clearable
                          v-model="form.questionCreatetime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="喜欢人数" prop="questionFavorcount">
          <el-input v-model="form.questionFavorcount" placeholder="请输入喜欢人数" />
        </el-form-item>
        <el-form-item label="收藏量" prop="questionCollectcount">
          <el-input v-model="form.questionCollectcount" placeholder="请输入收藏量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listQuestion, getQuestion, delQuestion, addQuestion, updateQuestion } from "@/api/qasystem/question";

export default {
  name: "Question",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 问题表格数据
      questionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        questionTitle: null,
        questionResume: null,
        questionUser: null,
        questionCreatetime: null,
        questionFavorcount: null,
        questionCollectcount: null,
        questionIsdel: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    labelquestion(){
      this.$router.push({path:'/labelquestion'});
    },
    handledetail(){
      this.$router.push({path:'/questiondetail'});
    },
    handletoallquestion(){
      this.$router.push({path:'/intoallquestion'});
    },

    allquestion(){
      this.getList();
    },
    hotanswer(){
      this.$router.push({path:'/answer'});
    },
    /** 查询问题列表 */
    getList() {
      this.loading = true;
      listQuestion(this.queryParams).then(response => {
        this.questionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        questionId: null,
        questionTitle: null,
        questionResume: null,
        questionUser: null,
        questionCreatetime: null,
        questionFavorcount: null,
        questionCollectcount: null,
        questionIsdel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.questionId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加问题";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const questionId = row.questionId || this.ids
      getQuestion(questionId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改问题";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.questionId != null) {
            updateQuestion(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuestion(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const questionIds = row.questionId || this.ids;
      this.$modal.confirm('是否确认删除问题编号为"' + questionIds + '"的数据项？').then(function() {
        return delQuestion(questionIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/question/export', {
        ...this.queryParams
      }, `question_${new Date().getTime()}.xlsx`)
    }
  }
};



</script>
<style >
body{text-align:center}
.php{margin:0 auto;width:400px;height:100px;border:1px solid #000}
</style>
<style rel="stylesheet/scss" lang="scss">
//.app-container {
  //display: flex;
  //justify-content: center;
  //align-items: center;
  //height: 50%;
  //background-image: url("../assets/images/shouy.jpg");
  //background-size: cover;


//}
//.app-container{
//  text-align: center; /*让div内部文字居中*/
//  background-color: #1ab394;
//  border-radius: 20px;
//  width: 1000px;
//  height: 600px;
//  margin: auto;
//  position: absolute;
//  top: 0;
//  left: 0;
//  right: 0;
//  bottom: 0;
//  //background-image: url("../assets/images/shouy.jpg");
//  //background-size: cover;
//}
.title {
  margin: 40px auto 60px auto;
  font-size: 30px;
  text-align: center;
  color: #1f2d3d;
}
.atitle{
  margin: 3px auto 20px auto;
  color: #1c84c6;

}
</style>
